package com.bawei.ivideo.test.mvi

import android.widget.Toast
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import com.bawei.ivideo.R
import com.bawei.ivideo.databinding.ActivityTestBinding
import com.bawei.library_mvi.ui.BaseMviActivity
import kotlinx.coroutines.launch

class TestActivity:BaseMviActivity<ActivityTestBinding>() {
    private lateinit var viewModel: TestViewModel
    //处理状态
    override fun handleState() {
        lifecycleScope.launch {
            viewModel.state.collect{
                when(it){
                    is TestUIState.Init -> {}
                    is TestUIState.MultiVideoState ->{
                        val list = it.list
                        Toast.makeText(this@TestActivity,list.toString(),Toast.LENGTH_SHORT).show()
                    }
                    is TestUIState.Error ->{
                        Toast.makeText(this@TestActivity,"失败"+it.exeception.message,Toast.LENGTH_SHORT).show()

                    }
                    is TestUIState.Empty ->{
                        Toast.makeText(this@TestActivity,"空",Toast.LENGTH_SHORT).show()

                    }
                }
            }
        }
    }

    override fun getLayout(): Int {
        return R.layout.activity_test
    }

    override fun initData() {
        super.initData()
        lifecycleScope.launch{
            viewModel.intents.send(TestIntent.MultiVideoIntent(1, 0))
        }
    }



    override fun generateViewModel() {
        viewModel = ViewModelProvider(this).get(TestViewModel::class.java)
    }

}